import {
  getNavRequest,
  addNavRequest,
  deteleNavRequest,
  editNavRequest
} from '@/service/nav/nav.js'
export default {
  state: {
    navList: []
  },
  mutations: {
    changeNav(state, nav) {
      state.navList = nav
    }
  },
  actions: {
    async requestNav({ commit }) {
      const navRes = await getNavRequest()
      commit('changeNav', navRes)
    },
    async addRequestNav({ dispatch, commit }, data) {
      await addNavRequest(data)
      dispatch('requestNav')
    },
    async deteleRequestNav({ dispatch, commit }, nId) {
      await deteleNavRequest({
        nId
      })
      dispatch('requestNav')
    },
    async EditRequestNav({ dispatch, commit }, data) {
      const navRes = await editNavRequest(data)
      dispatch('requestNav')
    }
  }
}
